/*-------------------------------------------------------------------------
 * 版权所有：	黑客马拉松
 * 作者：		罗毅
 * 联系方式：	whluoyi@gmail.com
 * 创建时间：	2016/10/29 11:23:16
 * 版本号：		v1.0
 * 用途描述：	控制器
 *  -------------------------------------------------------------------------*/

namespace SuperMarieApi.App.Controllers.V1
{
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Net.Http;
    using System.Web.Http;

    using SuperMarieApi.App.Controllers.Biz;
    using SuperMarieApi.App.Controllers.Entity;

    public class MyFaceSimilarityController : ApiController
    {
        public static List<MyFaceSimilarityEntity> Model = new List<MyFaceSimilarityEntity>();

        // GET api/MyFaceSimilarity
        public IEnumerable<MyFaceSimilarityEntity> Get()
        {
            return Model;
        }

        // GET api/MyFaceSimilarity/5
        public MyFaceSimilarityEntity Get(int id)
        {
            var entity = Model.FirstOrDefault(i => i.MyFaceSimilarity_ID == id);
            return entity;
        }

        // GET api/values/5?leval=1
        public HttpResponseMessage Get(int id, int leval)
        {
            return new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content =
                    new StringContent(
                    "<em style='color:red'>成功响应(id,level)</em>",
                    System.Text.Encoding.UTF8,
                    "text/html")
            };
        }

        // POST api/values
        public HttpResponseMessage Post([FromBody] MyFaceSimilarityEntity value)
        {
            MyFaceSimilarityEntity entity = new MyFaceSimilarityEntity();
            entity.MyFaceSimilarity_ID = value.MyFaceSimilarity_ID;
            entity.face_id = value.face_id;
            entity.other_face_id = value.other_face_id;
            entity.similarity = value.similarity;
            entity.AddTime = value.AddTime;
            MyFaceSimilarityBiz.InsertMyFaceSimilarityObj(entity);

            return new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content =
                    new StringContent(
                    "{\"error_code\": 0}",
                    System.Text.Encoding.UTF8,
                    "application/json")
            };
        }

        // PUT api/values?id=5
        public HttpResponseMessage Put(int id, [FromBody] MyFaceSimilarityEntity value)
        {
            var entity = Model.FirstOrDefault(i => i.MyFaceSimilarity_ID == id);
            entity.MyFaceSimilarity_ID = value.MyFaceSimilarity_ID;
            entity.face_id = value.face_id;
            entity.other_face_id = value.other_face_id;
            entity.similarity = value.similarity;
            entity.AddTime = value.AddTime;
            return new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content =
                    new StringContent(
                    "{\"error_code\": 0,\"}", System.Text.Encoding.UTF8,
                    "application/json")
            };
        }

        // DELETE api/values/5
        public HttpResponseMessage Delete(int id)
        {
            Model.Remove(Model.FirstOrDefault(i => i.MyFaceSimilarity_ID == id));
            return new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("删除数据成功") };
        }
    }
}